/**
 * @file igs_gpio.h
 * @author Sheng Wen Peng
 * @date 25 Nov 2014
 * @brief 
 */

#ifndef IGS_GPIO_H
#define IGS_GPIO_H

#include "stm32f2xx.h"
#include "igs_task.h"
#include "igs_queue.h"
#include "igs_protocol.h"

#define ENABLE_GPIO_MASK 1
#define DISABLE_GPIO_MASK 0
#define COMMAND_SWITCH_INIT 0x0
#define COMMAND_SWITCH_READ 0x1


#define GPIO_BUFFER_MAX 249

#define NUM_OF_SWITCH 8
#define NUM_OF_INPUT 8
#define NUM_OF_OUTPUT 15
#define BUFFER_SIZE 8
#define CEILING(x,y) (x-1)/y+1

#define NUM_OF_SWITCH_BUF CEILING(NUM_OF_SWITCH,BUFFER_SIZE)
#define NUM_OF_INPUT_BUF CEILING(NUM_OF_INPUT,BUFFER_SIZE)
#define NUM_OF_OUTPUT_BUF CEILING(NUM_OF_OUTPUT,BUFFER_SIZE)

typedef struct _gpio_map_t
{
	GPIO_TypeDef *group;
	uint32_t pin;
}gpio_map_t;

extern gpio_map_t output_map[NUM_OF_OUTPUT];

void igs_gpio_init(void);

void igs_gpio_toggle_led1(void);
void igs_gpio_toggle_led2(void);
void igs_gpio_toggle_led3(void);
void igs_gpio_set_led3(void);

void igs_gpio_set_input_mask(uint32_t id, uint8_t val);
void igs_gpio_set_output_mask(uint32_t id, uint8_t val);
void igs_gpio_set_switch_mask(uint32_t id, uint8_t val);

void igs_gpio_set_out_buf(uint32_t id, uint8_t val);
uint8_t igs_gpio_get_in_buf(uint32_t id);
uint8_t igs_gpio_get_switch_buf(uint32_t id);

void igs_gpio_set_out_real(uint32_t id, uint8_t val);
uint8_t igs_gpio_get_in_real(uint32_t id);
#endif
